import { RequestEnum } from '/@/enums/httpEnum';
// import { ErrorMessageMode } from '/#/axios';
import { BasicApi, BasicQueryParams } from '../basic';
import { defHttp, defHttpWithoutToken } from '/@/utils/http/axios';

enum URL {
  Login = '/core/login',
  Refresh = '/core/token_refresh',
  User = '/core/user',
}

/**
 * @description: Login interface parameters
 */
export interface LoginParams {
  username: string;
  password: string;
}

/**
 * @description: Refresh Token interface parameters
 */
export interface RefreshTokenParams {
  refresh: string;
}

/**
 * @description: Login interface return value
 */
export interface LoginResult {
  access: string;
  refresh: string;
}

/**
 * @description: User interface return value
 */
export interface UserResult {
  username: string;
}

export class AuthApi extends BasicApi<BasicQueryParams, UserResult> {
  /**
   *
   * 用户登录
   * @param params
   * @returns
   */
  public login(params: LoginParams): Promise<LoginResult> {
    return defHttpWithoutToken.request<LoginResult>({
      url: URL.Login,
      method: RequestEnum.POST,
      params: params,
    });
  }
  /**
   *
   * 刷新Token
   * @param {RefreshTokenParams} params
   * @return {*}  {Promise<LoginResult>}
   * @memberof AuthApi
   */
  public refreshToken(params: RefreshTokenParams): Promise<LoginResult> {
    return defHttpWithoutToken.request<LoginResult>({
      url: URL.Refresh,
      method: RequestEnum.POST,
      params,
    }) as Promise<LoginResult>;
  }

  /**
   * @description: 用户修改密码
   */
  public changePassword(id: string, params: any): Promise<LoginResult> {
    return defHttp.request({
      url: this.getUrl(id, 'change_password'),
      method: 'POST',
      params,
    });
  }
  /**
   *
   * @returns 获取权限代码
   */
  public listPermCodes(): Promise<string[]> {
    return new Promise((resolve) => {
      resolve([]);
    });
  }
}

export const authApi = new AuthApi(URL.User);
